import { queryDictAll } from "@/api/sysDict/sysDict";
import { defineStore } from "pinia";
import { ref } from "vue";

export default defineStore("appStore", () => {
    /**
     * 左侧菜单栏是否为折叠状态
     */
    const isFold = ref(false)
    /**
     * 是否需要刷新内容
     */
    const needRefresh = ref(false)
    /**
     * 字典
     */
    const dict = ref < Record<string, Record<string,string>>>();

    /**
     * 切换左侧菜单收缩/展开状态
     */
    const switchFold = () => {
        isFold.value = !isFold.value;
    };
    /**
     * 
     * @param need 切换是否需要刷新的状态
     */
    const setNeedRefresh = (need: boolean) => {
        needRefresh.value = need
    }
    /**
     * 加载所有字典信息
     */
    const loadDict = () => {
        queryDictAll()
            .then(map => dict.value = map);
    };

    return {
        isFold,
        needRefresh,
        dict,
        switchFold,
        setNeedRefresh,
        loadDict
    }
})